/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Ngocvan
 */
public class Point3D extends Point2D {
    private int z;

    public Point3D(int x, int y, int z) {
        super(x, y);
        this.z = z;
    }

    //-- violates symmetry
//    public boolean equals(Object o) {
//        if (!(o instanceof Point3D)) {
//            return false;
//        }
//        Point3D p3 = (Point3D) o;
//        return super.equals(o) && p3.z == z;
//    }


    //-- violates transitivity
    public boolean equals(Object o) {
        if (!(o instanceof Point2D)) {
            return false;
        }
        //-- if o is a Point2D, do an ignore-z comparison
        if (!(o instanceof Point3D)) {
            return o.equals(this);
        }

        //-- o must be a 3D point
        Point3D p3 = (Point3D) o;
        return super.equals(o) && p3.z == z;
    }


    public static void main(String[] args) {
        Point3D p1 = new Point3D(2, 3, 4);
        Point2D p2 = new Point2D(2, 3);
        Point3D p3 = new Point3D(2, 3, 12);

        System.out.println("Transitivity Test");
        System.out.println("p1.equals(p2) =>" + (p1.equals(p2) ? "true" : "false"));
        System.out.println("p2.equals(p3) =>" + (p2.equals(p3) ? "true" : "false"));
        System.out.println("p1.equals(p3) =>" + (p1.equals(p3) ? "true" : "false"));
    }
}
